<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/3 0003
  Time: 17:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑用户</title>
</head>
<style type="text/css">
    table{border: 1px solid #000000;
        border-collapse: collapse;
        align:center;
        margin: auto;
        vertical-align: middle;
    }
    h2{text-align:center}
    td,th{border: 1px solid #000000;
        padding: 8px;

    }
    p{align:center}
</style>
</head>
<body>
<%
    String id=request.getParameter("id");
    Connection connection=null;
    PreparedStatement statement=null;
    ResultSet resultSet=null;

    String sql="SELECT * FROM t_users WHERE id=?";

    Class.forName("com.mysql.jdbc.Driver");

    connection= DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?useUnicode=true&characterEncoding=UTF-8",
            "root",
            "123456"
    );
    statement=connection.prepareStatement(sql);
    statement.setString(1,id);
    resultSet=statement.executeQuery();
    if (resultSet.next()){
        String userId=resultSet.getString("id");
        String name=resultSet.getString("userName");
        String password=resultSet.getString("password");

%>
<h2>更新用户信息</h2>
<form name="form1" action="userUpdate.jsp" onSubmit="return check()" method="post">
    <table>
        <tr><th>编号：</th>
            <td><input type="text" name="id" value="<%=userId%>"></td>
        </tr>
        <tr><th>用户名：</th>
            <td><input type="text" name="userName" value="<%=name%>"></td>
        </tr>
        <tr>
            <th>密码：</th>
            <td><input type="text" name="password" value="<%=password%>"></td>
        </tr>
        <tr><th colspan="2">
            <input type="submit" value="更新">
            <input type="reset" value="重置"></th></tr>
    </table>
</form>
<%
    }
    resultSet.close();
    statement.close();
    connection.close();
%>
</body>
</html>
